<?php
class Shop_IndexController extends Zendvn_Controller_Action{
	
	public  function init(){
		
		$this->createTemplate(APPLICATION_PATH . '/templates/shop','template.ini','template');
		
	}
	
	public function indexAction(){
		
		$user_profile = array();
		
		$product_model = new Shop_Model_Product();
		
		$productid = @$_GET["product"];
		
		$product = $product_model->getItemById($productid);
		
		$shop_model = new Shop_Model_Index();
		
		$shop = $shop_model->getItemById($product["shopid"]);
		
		$this->view->product = $product;
		
		$this->view->shop = $shop;
		
	}
	
	public function updateorderAction(){
		
		if($this->getRequest()->isPost()){
			
			$displayname = @$_POST["displayname"];
			$email = @$_POST["email"];
			$phone = @$_POST["phone"];
			$address = @$_POST["address"];
			$district = @$_POST["district"];
			$province = @$_POST["province"];
			$payment_method = @$_POST["payment_method"];
			$number = @$_POST["number-product"];
			$note = @$_POST["note"];
			$productid = @$_POST["productid"];
			$shopid = @$_POST["shopid"];
			
			if($displayname != "" && $phone !="" && $address !="" && $district !="" && $province !="" && $productid != ""){
				
				$arr = array(
					"displayname"=>$displayname,
					"email"=>$email,
					"phone"=>$phone,
					"address"=>$address,
					"district"=>$district,
					"province"=>$province,					
				);
				
				$customer = new Shop_Model_Customer();
				$customerid = $customer->insertCustomer($arr);

				$order = new Shop_Model_Order();
				$arr = array(
					"customerid"=>$customerid,
					"productid"=>$productid,
					"shopid"=>$shopid,
					"payment_method"=>$payment_method,
					"number"=>$number,
					"total_paid"=>"",										
				);

				$order->insertOrder($arr);
				
			}
			
		}
		
	}
	
}